<?php

Class UpfileManager
{
    private $_pk = 'aid';

    private $_table = array(
        'table'  => 'upfiles',
        'fields' => array('shop_id', 'filename', 'memo', 'create_uid', 'create_dt'),
    );

    private $file_id = 0;

    public function __construct() {}

    public function setFileId($id) {
        $this->file_id = intval($id);
        $this->setField('aid', $this->file_id);
        return $this;
    }

    public function setField($field, $val) {
        $field = strtolower($field);
        $this->getTable()->set($field, $val);
        return $this;
    }

    public function getData() {
        $this->getTable()->get($this->file_id);
    }

    public function updateDb() {
        $this->getTable()->update($this->file_id);
    }

    public function insertDb() {
        if($this->file_id)
            $this->getTable()->set($this->_pk, $this->file_id)->insert();
        else
            $this->getTable()->insert();
    }

    public function getTable() {
        if(empty($this->_db)){
            $this->_db = new DbTable($this->_table['table'],  array($this->_pk, $this->_table['fields']));
        }
        return $this->_db;
    }
}
